package com.easy.cms.material.service;

import java.util.List;

import com.easy.cms.material.model.OrderMain;
import com.easy.cms.material.model.OrderSub;
import com.easy.cms.material.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;

public class OrderService {
    @Autowired
    private OrderRepository orderRepository;

    // 根据主订单编号查询订单
    public OrderMain getOrderByMainNumber(String mainOrderNumber) {
        return orderRepository.findByMainOrderNumber(mainOrderNumber);
    }

    // 根据主订单查子订单
    public List<OrderSub> getSubOrdersByMainNumber(String mainOrderNumber) {
        return orderRepository.findSubOrdersByMainOrderNumber(mainOrderNumber);
    }

    // 主订单列表接口
    public List<OrderMain> getOrderMainList() {
        return orderRepository.findAll();
    }

    // 保存订单到数据库
    public void saveOrder(OrderMain orderMain) {
        orderRepository.save(orderMain);
    }
}